package com.bird.send;

import com.alibaba.fastjson.JSONObject;
import com.bird.DTO.User;
import com.bird.config.RabbitmqProductConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @data 2021/9/12 17:07
 * @author: bird
 * @description: 发送消息
 */
@Slf4j
@Component
public class SendMessage {


    @Autowired
    private AmqpTemplate amqpTemplate;


    @Autowired
    private RabbitmqProductConfig rabbitmqConfig;


    public String sendMessage(User user) {
//        String data = JSONObject.toJSONString(user);
//        Message message = new Message(data.getBytes());
//        Message messageResponse = amqpTemplate.sendAndReceive(rabbitmqConfig.MATERIAL_CHANNEL_EXCHANGE, rabbitmqConfig.MATERIAL_CHANNEL_KEY, message);
//        System.out.println(messageResponse);

        amqpTemplate.convertAndSend(rabbitmqConfig.MATERIAL_CHANNEL_EXCHANGE, rabbitmqConfig.MATERIAL_CHANNEL_KEY,user);
        return "success";
    }

}
